package com.frxuexi.park2209.patrol

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.GridLayoutManager
import com.frxuexi.base.entity.PPointBean
import com.frxuexi.base.mvvm.BaseActivity
import com.frxuexi.park2209.R
import com.frxuexi.park2209.adapter.PointAdaoter
import com.frxuexi.park2209.databinding.ActivityAddPatrolBinding
import com.google.gson.Gson
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class AddPatrolActivity : BaseActivity<ActivityAddPatrolBinding,PatrolViewModel>() {
    val pointAdaoter by lazy { PointAdaoter() }
    override fun initData() {
        vm.selPointSuc.observe(this){
            val pPointBean = Gson().fromJson(it, PPointBean::class.java)
            pointAdaoter.addData(pPointBean)
            pointAdaoter.notifyDataSetChanged()
        }
    }

    override fun initView() {
        binding.rvPoint.apply {
            adapter=pointAdaoter
            layoutManager=GridLayoutManager(this@AddPatrolActivity,2)
        }

        var str=""
        pointAdaoter.setOnItemClickListener { adapter, view, position ->
            str+=pointAdaoter.data.get(position).pointName+","
            binding.tvSelectpoint.text=str
        }
        vm.selPoint()
    }

}